{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 本周知识-柱状图\n",
    "## 基本柱状图绘制"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "    <div class=\"bk-root\">\n",
       "        <a href=\"https://bokeh.org\" target=\"_blank\" class=\"bk-logo bk-logo-small bk-logo-notebook\"></a>\n",
       "        <span id=\"1001\">Loading BokehJS ...</span>\n",
       "    </div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "\n",
       "(function(root) {\n",
       "  function now() {\n",
       "    return new Date();\n",
       "  }\n",
       "\n",
       "  var force = true;\n",
       "\n",
       "  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n",
       "    root._bokeh_onload_callbacks = [];\n",
       "    root._bokeh_is_loading = undefined;\n",
       "  }\n",
       "\n",
       "  var JS_MIME_TYPE = 'application/javascript';\n",
       "  var HTML_MIME_TYPE = 'text/html';\n",
       "  var EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n",
       "  var CLASS_NAME = 'output_bokeh rendered_html';\n",
       "\n",
       "  /**\n",
       "   * Render data to the DOM node\n",
       "   */\n",
       "  function render(props, node) {\n",
       "    var script = document.createElement(\"script\");\n",
       "    node.appendChild(script);\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when an output is cleared or removed\n",
       "   */\n",
       "  function handleClearOutput(event, handle) {\n",
       "    var cell = handle.cell;\n",
       "\n",
       "    var id = cell.output_area._bokeh_element_id;\n",
       "    var server_id = cell.output_area._bokeh_server_id;\n",
       "    // Clean up Bokeh references\n",
       "    if (id != null && id in Bokeh.index) {\n",
       "      Bokeh.index[id].model.document.clear();\n",
       "      delete Bokeh.index[id];\n",
       "    }\n",
       "\n",
       "    if (server_id !== undefined) {\n",
       "      // Clean up Bokeh references\n",
       "      var cmd = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n",
       "      cell.notebook.kernel.execute(cmd, {\n",
       "        iopub: {\n",
       "          output: function(msg) {\n",
       "            var id = msg.content.text.trim();\n",
       "            if (id in Bokeh.index) {\n",
       "              Bokeh.index[id].model.document.clear();\n",
       "              delete Bokeh.index[id];\n",
       "            }\n",
       "          }\n",
       "        }\n",
       "      });\n",
       "      // Destroy server and session\n",
       "      var cmd = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n",
       "      cell.notebook.kernel.execute(cmd);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when a new output is added\n",
       "   */\n",
       "  function handleAddOutput(event, handle) {\n",
       "    var output_area = handle.output_area;\n",
       "    var output = handle.output;\n",
       "\n",
       "    // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n",
       "    if ((output.output_type != \"display_data\") || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n",
       "      return\n",
       "    }\n",
       "\n",
       "    var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n",
       "\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n",
       "      toinsert[toinsert.length - 1].firstChild.textContent = output.data[JS_MIME_TYPE];\n",
       "      // store reference to embed id on output_area\n",
       "      output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n",
       "    }\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n",
       "      var bk_div = document.createElement(\"div\");\n",
       "      bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n",
       "      var script_attrs = bk_div.children[0].attributes;\n",
       "      for (var i = 0; i < script_attrs.length; i++) {\n",
       "        toinsert[toinsert.length - 1].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n",
       "        toinsert[toinsert.length - 1].firstChild.textContent = bk_div.children[0].textContent\n",
       "      }\n",
       "      // store reference to server id on output_area\n",
       "      output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n",
       "    }\n",
       "  }\n",
       "\n",
       "  function register_renderer(events, OutputArea) {\n",
       "\n",
       "    function append_mime(data, metadata, element) {\n",
       "      // create a DOM node to render to\n",
       "      var toinsert = this.create_output_subarea(\n",
       "        metadata,\n",
       "        CLASS_NAME,\n",
       "        EXEC_MIME_TYPE\n",
       "      );\n",
       "      this.keyboard_manager.register_events(toinsert);\n",
       "      // Render to node\n",
       "      var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n",
       "      render(props, toinsert[toinsert.length - 1]);\n",
       "      element.append(toinsert);\n",
       "      return toinsert\n",
       "    }\n",
       "\n",
       "    /* Handle when an output is cleared or removed */\n",
       "    events.on('clear_output.CodeCell', handleClearOutput);\n",
       "    events.on('delete.Cell', handleClearOutput);\n",
       "\n",
       "    /* Handle when a new output is added */\n",
       "    events.on('output_added.OutputArea', handleAddOutput);\n",
       "\n",
       "    /**\n",
       "     * Register the mime type and append_mime function with output_area\n",
       "     */\n",
       "    OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n",
       "      /* Is output safe? */\n",
       "      safe: true,\n",
       "      /* Index of renderer in `output_area.display_order` */\n",
       "      index: 0\n",
       "    });\n",
       "  }\n",
       "\n",
       "  // register the mime type if in Jupyter Notebook environment and previously unregistered\n",
       "  if (root.Jupyter !== undefined) {\n",
       "    var events = require('base/js/events');\n",
       "    var OutputArea = require('notebook/js/outputarea').OutputArea;\n",
       "\n",
       "    if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n",
       "      register_renderer(events, OutputArea);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  \n",
       "  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n",
       "    root._bokeh_timeout = Date.now() + 5000;\n",
       "    root._bokeh_failed_load = false;\n",
       "  }\n",
       "\n",
       "  var NB_LOAD_WARNING = {'data': {'text/html':\n",
       "     \"<div style='background-color: #fdd'>\\n\"+\n",
       "     \"<p>\\n\"+\n",
       "     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n",
       "     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n",
       "     \"</p>\\n\"+\n",
       "     \"<ul>\\n\"+\n",
       "     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n",
       "     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n",
       "     \"</ul>\\n\"+\n",
       "     \"<code>\\n\"+\n",
       "     \"from bokeh.resources import INLINE\\n\"+\n",
       "     \"output_notebook(resources=INLINE)\\n\"+\n",
       "     \"</code>\\n\"+\n",
       "     \"</div>\"}};\n",
       "\n",
       "  function display_loaded() {\n",
       "    var el = document.getElementById(\"1001\");\n",
       "    if (el != null) {\n",
       "      el.textContent = \"BokehJS is loading...\";\n",
       "    }\n",
       "    if (root.Bokeh !== undefined) {\n",
       "      if (el != null) {\n",
       "        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n",
       "      }\n",
       "    } else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(display_loaded, 100)\n",
       "    }\n",
       "  }\n",
       "\n",
       "\n",
       "  function run_callbacks() {\n",
       "    try {\n",
       "      root._bokeh_onload_callbacks.forEach(function(callback) {\n",
       "        if (callback != null)\n",
       "          callback();\n",
       "      });\n",
       "    } finally {\n",
       "      delete root._bokeh_onload_callbacks\n",
       "    }\n",
       "    console.debug(\"Bokeh: all callbacks have finished\");\n",
       "  }\n",
       "\n",
       "  function load_libs(css_urls, js_urls, callback) {\n",
       "    if (css_urls == null) css_urls = [];\n",
       "    if (js_urls == null) js_urls = [];\n",
       "\n",
       "    root._bokeh_onload_callbacks.push(callback);\n",
       "    if (root._bokeh_is_loading > 0) {\n",
       "      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n",
       "      return null;\n",
       "    }\n",
       "    if (js_urls == null || js_urls.length === 0) {\n",
       "      run_callbacks();\n",
       "      return null;\n",
       "    }\n",
       "    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n",
       "    root._bokeh_is_loading = css_urls.length + js_urls.length;\n",
       "\n",
       "    function on_load() {\n",
       "      root._bokeh_is_loading--;\n",
       "      if (root._bokeh_is_loading === 0) {\n",
       "        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n",
       "        run_callbacks()\n",
       "      }\n",
       "    }\n",
       "\n",
       "    function on_error() {\n",
       "      console.error(\"failed to load \" + url);\n",
       "    }\n",
       "\n",
       "    for (var i = 0; i < css_urls.length; i++) {\n",
       "      var url = css_urls[i];\n",
       "      const element = document.createElement(\"link\");\n",
       "      element.onload = on_load;\n",
       "      element.onerror = on_error;\n",
       "      element.rel = \"stylesheet\";\n",
       "      element.type = \"text/css\";\n",
       "      element.href = url;\n",
       "      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n",
       "      document.body.appendChild(element);\n",
       "    }\n",
       "\n",
       "    const hashes = {\"https://cdn.bokeh.org/bokeh/release/bokeh-2.2.3.min.js\": \"T2yuo9Oe71Cz/I4X9Ac5+gpEa5a8PpJCDlqKYO0CfAuEszu1JrXLl8YugMqYe3sM\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.2.3.min.js\": \"98GDGJ0kOMCUMUePhksaQ/GYgB3+NH9h996V88sh3aOiUNX3N+fLXAtry6xctSZ6\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.2.3.min.js\": \"89bArO+nlbP3sgakeHjCo1JYxYR5wufVgA3IbUvDY+K7w4zyxJqssu7wVnfeKCq8\"};\n",
       "\n",
       "    for (var i = 0; i < js_urls.length; i++) {\n",
       "      var url = js_urls[i];\n",
       "      var element = document.createElement('script');\n",
       "      element.onload = on_load;\n",
       "      element.onerror = on_error;\n",
       "      element.async = false;\n",
       "      element.src = url;\n",
       "      if (url in hashes) {\n",
       "        element.crossOrigin = \"anonymous\";\n",
       "        element.integrity = \"sha384-\" + hashes[url];\n",
       "      }\n",
       "      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
       "      document.head.appendChild(element);\n",
       "    }\n",
       "  };\n",
       "\n",
       "  function inject_raw_css(css) {\n",
       "    const element = document.createElement(\"style\");\n",
       "    element.appendChild(document.createTextNode(css));\n",
       "    document.body.appendChild(element);\n",
       "  }\n",
       "\n",
       "  \n",
       "  var js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.2.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.2.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.2.3.min.js\"];\n",
       "  var css_urls = [];\n",
       "  \n",
       "\n",
       "  var inline_js = [\n",
       "    function(Bokeh) {\n",
       "      Bokeh.set_log_level(\"info\");\n",
       "    },\n",
       "    function(Bokeh) {\n",
       "    \n",
       "    \n",
       "    }\n",
       "  ];\n",
       "\n",
       "  function run_inline_js() {\n",
       "    \n",
       "    if (root.Bokeh !== undefined || force === true) {\n",
       "      \n",
       "    for (var i = 0; i < inline_js.length; i++) {\n",
       "      inline_js[i].call(root, root.Bokeh);\n",
       "    }\n",
       "    if (force === true) {\n",
       "        display_loaded();\n",
       "      }} else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(run_inline_js, 100);\n",
       "    } else if (!root._bokeh_failed_load) {\n",
       "      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n",
       "      root._bokeh_failed_load = true;\n",
       "    } else if (force !== true) {\n",
       "      var cell = $(document.getElementById(\"1001\")).parents('.cell').data().cell;\n",
       "      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n",
       "    }\n",
       "\n",
       "  }\n",
       "\n",
       "  if (root._bokeh_is_loading === 0) {\n",
       "    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n",
       "    run_inline_js();\n",
       "  } else {\n",
       "    load_libs(css_urls, js_urls, function() {\n",
       "      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n",
       "      run_inline_js();\n",
       "    });\n",
       "  }\n",
       "}(window));"
      ],
      "application/vnd.bokehjs_load.v0+json": "\n(function(root) {\n  function now() {\n    return new Date();\n  }\n\n  var force = true;\n\n  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n    root._bokeh_onload_callbacks = [];\n    root._bokeh_is_loading = undefined;\n  }\n\n  \n\n  \n  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n    root._bokeh_timeout = Date.now() + 5000;\n    root._bokeh_failed_load = false;\n  }\n\n  var NB_LOAD_WARNING = {'data': {'text/html':\n     \"<div style='background-color: #fdd'>\\n\"+\n     \"<p>\\n\"+\n     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n     \"</p>\\n\"+\n     \"<ul>\\n\"+\n     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n     \"</ul>\\n\"+\n     \"<code>\\n\"+\n     \"from bokeh.resources import INLINE\\n\"+\n     \"output_notebook(resources=INLINE)\\n\"+\n     \"</code>\\n\"+\n     \"</div>\"}};\n\n  function display_loaded() {\n    var el = document.getElementById(\"1001\");\n    if (el != null) {\n      el.textContent = \"BokehJS is loading...\";\n    }\n    if (root.Bokeh !== undefined) {\n      if (el != null) {\n        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n      }\n    } else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(display_loaded, 100)\n    }\n  }\n\n\n  function run_callbacks() {\n    try {\n      root._bokeh_onload_callbacks.forEach(function(callback) {\n        if (callback != null)\n          callback();\n      });\n    } finally {\n      delete root._bokeh_onload_callbacks\n    }\n    console.debug(\"Bokeh: all callbacks have finished\");\n  }\n\n  function load_libs(css_urls, js_urls, callback) {\n    if (css_urls == null) css_urls = [];\n    if (js_urls == null) js_urls = [];\n\n    root._bokeh_onload_callbacks.push(callback);\n    if (root._bokeh_is_loading > 0) {\n      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n      return null;\n    }\n    if (js_urls == null || js_urls.length === 0) {\n      run_callbacks();\n      return null;\n    }\n    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n    root._bokeh_is_loading = css_urls.length + js_urls.length;\n\n    function on_load() {\n      root._bokeh_is_loading--;\n      if (root._bokeh_is_loading === 0) {\n        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n        run_callbacks()\n      }\n    }\n\n    function on_error() {\n      console.error(\"failed to load \" + url);\n    }\n\n    for (var i = 0; i < css_urls.length; i++) {\n      var url = css_urls[i];\n      const element = document.createElement(\"link\");\n      element.onload = on_load;\n      element.onerror = on_error;\n      element.rel = \"stylesheet\";\n      element.type = \"text/css\";\n      element.href = url;\n      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n      document.body.appendChild(element);\n    }\n\n    const hashes = {\"https://cdn.bokeh.org/bokeh/release/bokeh-2.2.3.min.js\": \"T2yuo9Oe71Cz/I4X9Ac5+gpEa5a8PpJCDlqKYO0CfAuEszu1JrXLl8YugMqYe3sM\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.2.3.min.js\": \"98GDGJ0kOMCUMUePhksaQ/GYgB3+NH9h996V88sh3aOiUNX3N+fLXAtry6xctSZ6\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.2.3.min.js\": \"89bArO+nlbP3sgakeHjCo1JYxYR5wufVgA3IbUvDY+K7w4zyxJqssu7wVnfeKCq8\"};\n\n    for (var i = 0; i < js_urls.length; i++) {\n      var url = js_urls[i];\n      var element = document.createElement('script');\n      element.onload = on_load;\n      element.onerror = on_error;\n      element.async = false;\n      element.src = url;\n      if (url in hashes) {\n        element.crossOrigin = \"anonymous\";\n        element.integrity = \"sha384-\" + hashes[url];\n      }\n      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n      document.head.appendChild(element);\n    }\n  };\n\n  function inject_raw_css(css) {\n    const element = document.createElement(\"style\");\n    element.appendChild(document.createTextNode(css));\n    document.body.appendChild(element);\n  }\n\n  \n  var js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.2.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.2.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.2.3.min.js\"];\n  var css_urls = [];\n  \n\n  var inline_js = [\n    function(Bokeh) {\n      Bokeh.set_log_level(\"info\");\n    },\n    function(Bokeh) {\n    \n    \n    }\n  ];\n\n  function run_inline_js() {\n    \n    if (root.Bokeh !== undefined || force === true) {\n      \n    for (var i = 0; i < inline_js.length; i++) {\n      inline_js[i].call(root, root.Bokeh);\n    }\n    if (force === true) {\n        display_loaded();\n      }} else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(run_inline_js, 100);\n    } else if (!root._bokeh_failed_load) {\n      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n      root._bokeh_failed_load = true;\n    } else if (force !== true) {\n      var cell = $(document.getElementById(\"1001\")).parents('.cell').data().cell;\n      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n    }\n\n  }\n\n  if (root._bokeh_is_loading === 0) {\n    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n    run_inline_js();\n  } else {\n    load_libs(css_urls, js_urls, function() {\n      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n      run_inline_js();\n    });\n  }\n}(window));"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.plotting import output_notebook,figure,show\n",
    "output_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 垂直柱状图\n",
    "* 绘制方法\n",
    "> vbar( )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 查看使用方法\n",
    "# help(p.vbar()) or ??p.vbar"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"6a31214f-0f3f-4ad3-bd75-b386c105df06\" data-root-id=\"1002\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"2d7c3537-1fcd-468b-b98c-4266b55842db\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1011\"}],\"center\":[{\"id\":\"1014\"},{\"id\":\"1018\"}],\"left\":[{\"id\":\"1015\"}],\"plot_height\":400,\"plot_width\":400,\"renderers\":[{\"id\":\"1036\"}],\"title\":{\"id\":\"1039\"},\"toolbar\":{\"id\":\"1026\"},\"x_range\":{\"id\":\"1003\"},\"x_scale\":{\"id\":\"1007\"},\"y_range\":{\"id\":\"1005\"},\"y_scale\":{\"id\":\"1009\"}},\"id\":\"1002\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1012\",\"type\":\"BasicTicker\"},{\"attributes\":{\"formatter\":{\"id\":\"1042\"},\"ticker\":{\"id\":\"1012\"}},\"id\":\"1011\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1009\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1024\",\"type\":\"HelpTool\"},{\"attributes\":{\"axis\":{\"id\":\"1011\"},\"ticker\":null},\"id\":\"1014\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1040\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"axis\":{\"id\":\"1015\"},\"dimension\":1,\"ticker\":null},\"id\":\"1018\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1016\",\"type\":\"BasicTicker\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1019\"},{\"id\":\"1020\"},{\"id\":\"1021\"},{\"id\":\"1022\"},{\"id\":\"1023\"},{\"id\":\"1024\"}]},\"id\":\"1026\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1020\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1019\",\"type\":\"PanTool\"},{\"attributes\":{\"overlay\":{\"id\":\"1025\"}},\"id\":\"1021\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1007\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1022\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1042\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1023\",\"type\":\"ResetTool\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"red\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"red\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.5},\"x\":{\"field\":\"x\"}},\"id\":\"1035\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1005\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1045\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"source\":{\"id\":\"1033\"}},\"id\":\"1037\",\"type\":\"CDSView\"},{\"attributes\":{\"data_source\":{\"id\":\"1033\"},\"glyph\":{\"id\":\"1034\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1035\"},\"selection_glyph\":null,\"view\":{\"id\":\"1037\"}},\"id\":\"1036\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1046\",\"type\":\"Selection\"},{\"attributes\":{\"text\":\"\"},\"id\":\"1039\",\"type\":\"Title\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1025\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"fill_color\":{\"value\":\"red\"},\"line_color\":{\"value\":\"red\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.5},\"x\":{\"field\":\"x\"}},\"id\":\"1034\",\"type\":\"VBar\"},{\"attributes\":{\"data\":{\"top\":[1.2,2.5,3.7],\"x\":[1,2,3]},\"selected\":{\"id\":\"1046\"},\"selection_policy\":{\"id\":\"1045\"}},\"id\":\"1033\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"formatter\":{\"id\":\"1040\"},\"ticker\":{\"id\":\"1016\"}},\"id\":\"1015\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1003\",\"type\":\"DataRange1d\"}],\"root_ids\":[\"1002\"]},\"title\":\"Bokeh Application\",\"version\":\"2.2.3\"}};\n",
       "  var render_items = [{\"docid\":\"2d7c3537-1fcd-468b-b98c-4266b55842db\",\"root_ids\":[\"1002\"],\"roots\":{\"1002\":\"6a31214f-0f3f-4ad3-bd75-b386c105df06\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1002"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 画布\n",
    "p = figure(plot_width=400, plot_height=400)\n",
    "p.vbar(x=[1, 2, 3], \n",
    "       width=0.5, \n",
    "       bottom=0,\n",
    "       top=[1.2, 2.5, 3.7], \n",
    "       color=\"red\")  # 垂直柱状图\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 水平的柱状图\n",
    "* 绘制方法\n",
    "> hbar( )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 查看使用方法\n",
    "# help(p.hbar()) or ?? p.hbar"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"44b92fec-689f-4e62-933a-7cb2b1a11037\" data-root-id=\"1092\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"17e88a18-094f-49ad-86f9-a58b31d76f71\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1103\"}],\"center\":[{\"id\":\"1106\"},{\"id\":\"1110\"}],\"left\":[{\"id\":\"1107\"}],\"plot_height\":200,\"plot_width\":400,\"renderers\":[{\"id\":\"1128\"}],\"title\":{\"id\":\"1093\"},\"toolbar\":{\"id\":\"1118\"},\"x_range\":{\"id\":\"1095\"},\"x_scale\":{\"id\":\"1099\"},\"y_range\":{\"id\":\"1097\"},\"y_scale\":{\"id\":\"1101\"}},\"id\":\"1092\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"source\":{\"id\":\"1125\"}},\"id\":\"1129\",\"type\":\"CDSView\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1117\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"navy\"},\"height\":{\"value\":0.25},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"navy\"},\"right\":{\"field\":\"right\"},\"y\":{\"field\":\"y\"}},\"id\":\"1127\",\"type\":\"HBar\"},{\"attributes\":{\"formatter\":{\"id\":\"1142\"},\"ticker\":{\"id\":\"1104\"}},\"id\":\"1103\",\"type\":\"LinearAxis\"},{\"attributes\":{\"data\":{\"right\":[1.2,2.5,3.7],\"y\":[1,2,3]},\"selected\":{\"id\":\"1146\"},\"selection_policy\":{\"id\":\"1145\"}},\"id\":\"1125\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"data_source\":{\"id\":\"1125\"},\"glyph\":{\"id\":\"1126\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1127\"},\"selection_glyph\":null,\"view\":{\"id\":\"1129\"}},\"id\":\"1128\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1111\"},{\"id\":\"1112\"},{\"id\":\"1113\"},{\"id\":\"1114\"},{\"id\":\"1115\"},{\"id\":\"1116\"}]},\"id\":\"1118\",\"type\":\"Toolbar\"},{\"attributes\":{\"fill_color\":{\"value\":\"navy\"},\"height\":{\"value\":0.25},\"line_color\":{\"value\":\"navy\"},\"right\":{\"field\":\"right\"},\"y\":{\"field\":\"y\"}},\"id\":\"1126\",\"type\":\"HBar\"},{\"attributes\":{\"text\":\"\\u6c34\\u5e73\\u67f1\\u72b6\\u56fe\"},\"id\":\"1093\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1095\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1097\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1140\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1112\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1142\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1104\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1101\",\"type\":\"LinearScale\"},{\"attributes\":{\"formatter\":{\"id\":\"1140\"},\"ticker\":{\"id\":\"1108\"}},\"id\":\"1107\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1099\",\"type\":\"LinearScale\"},{\"attributes\":{\"axis\":{\"id\":\"1103\"},\"ticker\":null},\"id\":\"1106\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1116\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"1145\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1146\",\"type\":\"Selection\"},{\"attributes\":{\"axis\":{\"id\":\"1107\"},\"dimension\":1,\"ticker\":null},\"id\":\"1110\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1108\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1111\",\"type\":\"PanTool\"},{\"attributes\":{\"overlay\":{\"id\":\"1117\"}},\"id\":\"1113\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1114\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1115\",\"type\":\"ResetTool\"}],\"root_ids\":[\"1092\"]},\"title\":\"Bokeh Application\",\"version\":\"2.2.3\"}};\n",
       "  var render_items = [{\"docid\":\"17e88a18-094f-49ad-86f9-a58b31d76f71\",\"root_ids\":[\"1092\"],\"roots\":{\"1092\":\"44b92fec-689f-4e62-933a-7cb2b1a11037\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1092"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "p = figure(plot_width=400, plot_height=200,title=\"水平柱状图\")\n",
    "p.hbar(y=[1, 2, 3], \n",
    "       height=0.25, \n",
    "       left=0,\n",
    "       right=[1.2, 2.5, 3.7], \n",
    "       color=\"navy\")  # 水平柱状图\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 演示1. 水果数量锤子柱状图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"0de7cb48-6f74-429c-b99f-bfcc583dea89\" data-root-id=\"1188\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"a582f001-cf93-4b71-a11b-13f3d096e892\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1199\"}],\"center\":[{\"id\":\"1201\"},{\"id\":\"1205\"}],\"left\":[{\"id\":\"1202\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"1225\"}],\"title\":{\"id\":\"1189\"},\"toolbar\":{\"id\":\"1214\"},\"x_range\":{\"id\":\"1191\"},\"x_scale\":{\"id\":\"1195\"},\"y_range\":{\"id\":\"1193\"},\"y_scale\":{\"id\":\"1197\"}},\"id\":\"1188\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1203\",\"type\":\"BasicTicker\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"\\u6c34\\u679c\\u540d\\u79f0\",\"@x\"],[\"\\u6570\\u91cf\",\"@counts\"]]},\"id\":\"1213\",\"type\":\"HoverTool\"},{\"attributes\":{\"data_source\":{\"id\":\"1187\"},\"glyph\":{\"id\":\"1223\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1224\"},\"selection_glyph\":null,\"view\":{\"id\":\"1226\"}},\"id\":\"1225\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1206\"},{\"id\":\"1207\"},{\"id\":\"1208\"},{\"id\":\"1209\"},{\"id\":\"1210\"},{\"id\":\"1211\"},{\"id\":\"1213\"}]},\"id\":\"1214\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1207\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"source\":{\"id\":\"1187\"}},\"id\":\"1226\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1206\",\"type\":\"PanTool\"},{\"attributes\":{\"overlay\":{\"id\":\"1212\"}},\"id\":\"1208\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1209\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1210\",\"type\":\"ResetTool\"},{\"attributes\":{\"data\":{\"counts\":[5,3,4,2,4,6],\"x\":[\"Apples\",\"Pears\",\"Nectarines\",\"Plums\",\"Grapes\",\"Strawberries\"]},\"selected\":{\"id\":\"1251\"},\"selection_policy\":{\"id\":\"1250\"}},\"id\":\"1187\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"fill_color\":{\"value\":\"orange\"},\"line_color\":{\"value\":\"orange\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.85},\"x\":{\"field\":\"x\"}},\"id\":\"1223\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1250\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1251\",\"type\":\"Selection\"},{\"attributes\":{\"text\":\"Fruit Counts\"},\"id\":\"1189\",\"type\":\"Title\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1212\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"orange\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"orange\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.85},\"x\":{\"field\":\"x\"}},\"id\":\"1224\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1245\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1197\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1195\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"formatter\":{\"id\":\"1247\"},\"ticker\":{\"id\":\"1200\"}},\"id\":\"1199\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"factors\":[\"Apples\",\"Pears\",\"Nectarines\",\"Plums\",\"Grapes\",\"Strawberries\"]},\"id\":\"1191\",\"type\":\"FactorRange\"},{\"attributes\":{\"formatter\":{\"id\":\"1245\"},\"ticker\":{\"id\":\"1203\"}},\"id\":\"1202\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1211\",\"type\":\"HelpTool\"},{\"attributes\":{\"start\":0},\"id\":\"1193\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1200\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"axis\":{\"id\":\"1199\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"1201\",\"type\":\"Grid\"},{\"attributes\":{\"axis\":{\"id\":\"1202\"},\"dimension\":1,\"ticker\":null},\"id\":\"1205\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1247\",\"type\":\"CategoricalTickFormatter\"}],\"root_ids\":[\"1188\"]},\"title\":\"Bokeh Application\",\"version\":\"2.2.3\"}};\n",
       "  var render_items = [{\"docid\":\"a582f001-cf93-4b71-a11b-13f3d096e892\",\"root_ids\":[\"1188\"],\"roots\":{\"1188\":\"0de7cb48-6f74-429c-b99f-bfcc583dea89\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1188"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.models import ColumnDataSource\n",
    "# 数据准备 (名称和值)\n",
    "fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']\n",
    "counts = [5, 3, 4, 2, 4, 6]\n",
    "source = ColumnDataSource(data=dict(\n",
    "    x=fruits,\n",
    "    counts=counts\n",
    "    ))\n",
    "#交互\n",
    "TOOLTIPS = [\n",
    "    (\"水果名称\", '@x'),\n",
    "    (\"数量\", \"@counts\")\n",
    "]\n",
    "# 画布\n",
    "p = figure(x_range=fruits, \n",
    "           plot_height=350, \n",
    "           title=\"Fruit Counts\",\n",
    "           tooltips=TOOLTIPS\n",
    "         )\n",
    "# 绘制\n",
    "p.vbar(x='x', \n",
    "       top='counts', \n",
    "       width=0.85,\n",
    "      source=source,\n",
    "      color=\"orange\")\n",
    "\n",
    "p.xgrid.grid_line_color = None\n",
    "p.y_range.start = 0\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 实践2 数据源链接[数据源](https://gitee.com/xzhichao/interactive-data-visualization/blob/master/week06/data/visualization-20190505.csv)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Visualization_tools</th>\n",
       "      <th>Watch</th>\n",
       "      <th>Star</th>\n",
       "      <th>Fork</th>\n",
       "      <th>Commits</th>\n",
       "      <th>Contributors</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>matplotlib</td>\n",
       "      <td>533</td>\n",
       "      <td>9678</td>\n",
       "      <td>4143</td>\n",
       "      <td>29503</td>\n",
       "      <td>808</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>bokeh</td>\n",
       "      <td>396</td>\n",
       "      <td>11034</td>\n",
       "      <td>2526</td>\n",
       "      <td>17673</td>\n",
       "      <td>357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>pyecharts</td>\n",
       "      <td>263</td>\n",
       "      <td>5387</td>\n",
       "      <td>1148</td>\n",
       "      <td>1321</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>seaborn</td>\n",
       "      <td>234</td>\n",
       "      <td>6038</td>\n",
       "      <td>970</td>\n",
       "      <td>2316</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>plotly</td>\n",
       "      <td>234</td>\n",
       "      <td>4928</td>\n",
       "      <td>1114</td>\n",
       "      <td>3370</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>ggplot2</td>\n",
       "      <td>329</td>\n",
       "      <td>3783</td>\n",
       "      <td>1427</td>\n",
       "      <td>4286</td>\n",
       "      <td>184</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Visualization_tools  Watch   Star  Fork  Commits  Contributors\n",
       "0          matplotlib    533   9678  4143    29503           808\n",
       "1               bokeh    396  11034  2526    17673           357\n",
       "2           pyecharts    263   5387  1148     1321            18\n",
       "3             seaborn    234   6038   970     2316            98\n",
       "4              plotly    234   4928  1114     3370            76\n",
       "5             ggplot2    329   3783  1427     4286           184"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 数据处理\n",
    "import pandas as pd\n",
    "df=pd.read_csv('week6_data.csv')\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0     9678\n",
       "1    11034\n",
       "2     5387\n",
       "3     6038\n",
       "4     4928\n",
       "5     3783\n",
       "Name: Star, dtype: int64"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "0    matplotlib\n",
       "1         bokeh\n",
       "2     pyecharts\n",
       "3       seaborn\n",
       "4        plotly\n",
       "5       ggplot2\n",
       "Name: Visualization_tools, dtype: object"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display(df['Star'])\n",
    "display(df['Visualization_tools'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"dd41e577-f34f-460e-8f03-2409f84befb0\" data-root-id=\"1293\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"486c7e1d-4541-4198-922b-c1720ef7dea0\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1304\"}],\"center\":[{\"id\":\"1306\"},{\"id\":\"1310\"},{\"id\":\"1340\"}],\"left\":[{\"id\":\"1307\"}],\"plot_height\":450,\"renderers\":[{\"id\":\"1330\"}],\"title\":{\"id\":\"1294\"},\"toolbar\":{\"id\":\"1319\"},\"x_range\":{\"id\":\"1296\"},\"x_scale\":{\"id\":\"1300\"},\"y_range\":{\"id\":\"1298\"},\"y_scale\":{\"id\":\"1302\"}},\"id\":\"1293\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"color\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"field\":\"color\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.85},\"x\":{\"field\":\"x\"}},\"id\":\"1329\",\"type\":\"VBar\"},{\"attributes\":{\"text\":\"2019\\u5e74\\u53ef\\u89c6\\u5316\\u5de5\\u5177\\u6807\\u661f\\u6570\\u91cf\"},\"id\":\"1294\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1302\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1333\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1300\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"formatter\":{\"id\":\"1335\"},\"ticker\":{\"id\":\"1305\"}},\"id\":\"1304\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"factors\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"id\":\"1296\",\"type\":\"FactorRange\"},{\"attributes\":{\"formatter\":{\"id\":\"1333\"},\"ticker\":{\"id\":\"1308\"}},\"id\":\"1307\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1316\",\"type\":\"HelpTool\"},{\"attributes\":{\"start\":0},\"id\":\"1298\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1305\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"axis\":{\"id\":\"1304\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"1306\",\"type\":\"Grid\"},{\"attributes\":{\"axis\":{\"id\":\"1307\"},\"dimension\":1,\"ticker\":null},\"id\":\"1310\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1308\",\"type\":\"BasicTicker\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"\\u53ef\\u89c6\\u5316\\u5de5\\u5177\\u540d\\u79f0\",\"@x\"],[\"star\\u6570\\u91cf\",\"@counts\"]]},\"id\":\"1318\",\"type\":\"HoverTool\"},{\"attributes\":{\"items\":[{\"id\":\"1341\"}],\"location\":\"top_center\",\"orientation\":\"horizontal\"},\"id\":\"1340\",\"type\":\"Legend\"},{\"attributes\":{},\"id\":\"1338\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1312\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1339\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1311\",\"type\":\"PanTool\"},{\"attributes\":{\"overlay\":{\"id\":\"1317\"}},\"id\":\"1313\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1314\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1315\",\"type\":\"ResetTool\"},{\"attributes\":{\"data_source\":{\"id\":\"1292\"},\"glyph\":{\"id\":\"1328\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1329\"},\"selection_glyph\":null,\"view\":{\"id\":\"1331\"}},\"id\":\"1330\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1311\"},{\"id\":\"1312\"},{\"id\":\"1313\"},{\"id\":\"1314\"},{\"id\":\"1315\"},{\"id\":\"1316\"},{\"id\":\"1318\"}]},\"id\":\"1319\",\"type\":\"Toolbar\"},{\"attributes\":{\"source\":{\"id\":\"1292\"}},\"id\":\"1331\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1335\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"fill_color\":{\"field\":\"color\"},\"line_color\":{\"field\":\"color\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.85},\"x\":{\"field\":\"x\"}},\"id\":\"1328\",\"type\":\"VBar\"},{\"attributes\":{\"label\":{\"field\":\"x\"},\"renderers\":[{\"id\":\"1330\"}]},\"id\":\"1341\",\"type\":\"LegendItem\"},{\"attributes\":{\"data\":{\"color\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"],\"counts\":[9678,11034,5387,6038,4928,3783],\"x\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"selected\":{\"id\":\"1339\"},\"selection_policy\":{\"id\":\"1338\"}},\"id\":\"1292\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1317\",\"type\":\"BoxAnnotation\"}],\"root_ids\":[\"1293\"]},\"title\":\"Bokeh Application\",\"version\":\"2.2.3\"}};\n",
       "  var render_items = [{\"docid\":\"486c7e1d-4541-4198-922b-c1720ef7dea0\",\"root_ids\":[\"1293\"],\"roots\":{\"1293\":\"dd41e577-f34f-460e-8f03-2409f84befb0\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1293"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.models import ColumnDataSource\n",
    "from bokeh.palettes import Spectral6\n",
    "# 数据处理\n",
    "source = ColumnDataSource(data=dict(\n",
    "    x=df['Visualization_tools'],\n",
    "    counts=df['Star'],\n",
    "    color=Spectral6\n",
    "    ))\n",
    "#交互\n",
    "TOOLTIPS = [\n",
    "    (\"可视化工具名称\", '@x'),\n",
    "    (\"star数量\", \"@counts\")\n",
    "]\n",
    "\n",
    "p = figure(x_range=df['Visualization_tools'],\n",
    "           plot_height=450,\n",
    "           title=\"2019年可视化工具标星数量\",\n",
    "          tooltips=TOOLTIPS)\n",
    "\n",
    "p.vbar(x='x', \n",
    "       top='counts', \n",
    "       color=\"color\",\n",
    "       width=0.85,\n",
    "      source=source,\n",
    "      legend=\"x\")\n",
    "\n",
    "p.xgrid.grid_line_color = None\n",
    "p.y_range.start = 0\n",
    "p.legend.orientation = \"horizontal\"\n",
    "p.legend.location = \"top_center\"\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 分组柱状图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('Apples', '2015'),\n",
       " ('Apples', '2016'),\n",
       " ('Apples', '2017'),\n",
       " ('Pears', '2015'),\n",
       " ('Pears', '2016'),\n",
       " ('Pears', '2017'),\n",
       " ('Nectarines', '2015'),\n",
       " ('Nectarines', '2016'),\n",
       " ('Nectarines', '2017'),\n",
       " ('Plums', '2015'),\n",
       " ('Plums', '2016'),\n",
       " ('Plums', '2017'),\n",
       " ('Grapes', '2015'),\n",
       " ('Grapes', '2016'),\n",
       " ('Grapes', '2017'),\n",
       " ('Strawberries', '2015'),\n",
       " ('Strawberries', '2016'),\n",
       " ('Strawberries', '2017')]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']\n",
    "years = ['2015', '2016', '2017']\n",
    "data = {'fruits' : fruits,\n",
    "        '2015'   : [2, 1, 4, 3, 2, 4],\n",
    "        '2016'   : [5, 3, 3, 2, 4, 6],\n",
    "        '2017'   : [3, 2, 4, 4, 5, 3]}\n",
    "x = [ (fruit, year) for fruit in fruits for year in years ]\n",
    "x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 课后实践 Star commit contributors 分组柱状图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    matplotlib\n",
       "1         bokeh\n",
       "2     pyecharts\n",
       "3       seaborn\n",
       "4        plotly\n",
       "5       ggplot2\n",
       "Name: Visualization_tools, dtype: object"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "0     9678\n",
       "1    11034\n",
       "2     5387\n",
       "3     6038\n",
       "4     4928\n",
       "5     3783\n",
       "Name: Star, dtype: int64"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "0    29503\n",
       "1    17673\n",
       "2     1321\n",
       "3     2316\n",
       "4     3370\n",
       "5     4286\n",
       "Name: Commits, dtype: int64"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "0    808\n",
       "1    357\n",
       "2     18\n",
       "3     98\n",
       "4     76\n",
       "5    184\n",
       "Name: Contributors, dtype: int64"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display(df['Visualization_tools'])\n",
    "display(df['Star'])\n",
    "display(df['Commits'])\n",
    "display(df['Contributors'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"3d972163-0f57-41ae-8f26-947412363479\" data-root-id=\"1944\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"ebddd54f-cc56-44e2-b199-754793a5ca2b\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1954\"}],\"center\":[{\"id\":\"1956\"},{\"id\":\"1960\"}],\"left\":[{\"id\":\"1957\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"1980\"}],\"title\":{\"id\":\"1945\"},\"toolbar\":{\"id\":\"1969\"},\"x_range\":{\"id\":\"1943\"},\"x_scale\":{\"id\":\"1950\"},\"y_range\":{\"id\":\"1948\"},\"y_scale\":{\"id\":\"1952\"}},\"id\":\"1944\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"axis\":{\"id\":\"1954\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"1956\",\"type\":\"Grid\"},{\"attributes\":{\"source\":{\"id\":\"1942\"}},\"id\":\"1981\",\"type\":\"CDSView\"},{\"attributes\":{\"formatter\":{\"id\":\"2048\"},\"ticker\":{\"id\":\"1958\"}},\"id\":\"1957\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1966\",\"type\":\"HelpTool\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"\\u53ef\\u89c6\\u5316\\u5de5\\u5177\\u540d\\u79f0\",\"@x\"],[\"\\u6570\\u91cf\",\"@counts\"]]},\"id\":\"1968\",\"type\":\"HoverTool\"},{\"attributes\":{},\"id\":\"1955\",\"type\":\"CategoricalTicker\"},{\"attributes\":{},\"id\":\"2053\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"2054\",\"type\":\"Selection\"},{\"attributes\":{\"axis\":{\"id\":\"1957\"},\"dimension\":1,\"ticker\":null},\"id\":\"1960\",\"type\":\"Grid\"},{\"attributes\":{\"data\":{\"counts\":[9678,29503,808,11034,17673,357,5387,1321,18,6038,2316,98,4928,3370,76,3783,4286,184],\"x\":[[\"matplotlib\",\"Star\"],[\"matplotlib\",\"Commits\"],[\"matplotlib\",\"Contributors\"],[\"bokeh\",\"Star\"],[\"bokeh\",\"Commits\"],[\"bokeh\",\"Contributors\"],[\"pyecharts\",\"Star\"],[\"pyecharts\",\"Commits\"],[\"pyecharts\",\"Contributors\"],[\"seaborn\",\"Star\"],[\"seaborn\",\"Commits\"],[\"seaborn\",\"Contributors\"],[\"plotly\",\"Star\"],[\"plotly\",\"Commits\"],[\"plotly\",\"Contributors\"],[\"ggplot2\",\"Star\"],[\"ggplot2\",\"Commits\"],[\"ggplot2\",\"Contributors\"]]},\"selected\":{\"id\":\"2054\"},\"selection_policy\":{\"id\":\"2053\"}},\"id\":\"1942\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1978\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1958\",\"type\":\"BasicTicker\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1979\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1962\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1961\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1952\",\"type\":\"LinearScale\"},{\"attributes\":{\"overlay\":{\"id\":\"1967\"}},\"id\":\"1963\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1964\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1965\",\"type\":\"ResetTool\"},{\"attributes\":{\"text\":\"\\u53ef\\u89c6\\u5316\\u5de5\\u5177Star commit contributors \\u6570\\u91cf\"},\"id\":\"1945\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"2048\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"start\":0},\"id\":\"1948\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1950\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1967\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"formatter\":{\"id\":\"2050\"},\"major_label_orientation\":1,\"ticker\":{\"id\":\"1955\"}},\"id\":\"1954\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"2050\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"factors\":[[\"matplotlib\",\"Star\"],[\"matplotlib\",\"Commits\"],[\"matplotlib\",\"Contributors\"],[\"bokeh\",\"Star\"],[\"bokeh\",\"Commits\"],[\"bokeh\",\"Contributors\"],[\"pyecharts\",\"Star\"],[\"pyecharts\",\"Commits\"],[\"pyecharts\",\"Contributors\"],[\"seaborn\",\"Star\"],[\"seaborn\",\"Commits\"],[\"seaborn\",\"Contributors\"],[\"plotly\",\"Star\"],[\"plotly\",\"Commits\"],[\"plotly\",\"Contributors\"],[\"ggplot2\",\"Star\"],[\"ggplot2\",\"Commits\"],[\"ggplot2\",\"Contributors\"]],\"range_padding\":0.1},\"id\":\"1943\",\"type\":\"FactorRange\"},{\"attributes\":{\"data_source\":{\"id\":\"1942\"},\"glyph\":{\"id\":\"1978\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1979\"},\"selection_glyph\":null,\"view\":{\"id\":\"1981\"}},\"id\":\"1980\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1961\"},{\"id\":\"1962\"},{\"id\":\"1963\"},{\"id\":\"1964\"},{\"id\":\"1965\"},{\"id\":\"1966\"},{\"id\":\"1968\"}]},\"id\":\"1969\",\"type\":\"Toolbar\"}],\"root_ids\":[\"1944\"]},\"title\":\"Bokeh Application\",\"version\":\"2.2.3\"}};\n",
       "  var render_items = [{\"docid\":\"ebddd54f-cc56-44e2-b199-754793a5ca2b\",\"root_ids\":[\"1944\"],\"roots\":{\"1944\":\"3d972163-0f57-41ae-8f26-947412363479\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1944"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.models import ColumnDataSource, FactorRange\n",
    "tools=df['Visualization_tools']\n",
    "Star=df['Star']\n",
    "Commits=df['Commits']\n",
    "Contributors=df['Contributors']\n",
    "names=['Star','Commits','Contributors']\n",
    "data={\n",
    "    'tools':tools,\n",
    "    'Star':Star,\n",
    "    'Commits':Commits,\n",
    "    'Contributors':Contributors\n",
    "}\n",
    "x = [ (tool, name) for tool in tools for name in names ]\n",
    "counts = sum(zip(data['Star'], data['Commits'], data['Contributors']), ()) # 分组求和(堆叠总数)\n",
    "source = ColumnDataSource(data=dict(x=x, counts=counts))\n",
    "TOOLTIPS = [\n",
    "    (\"可视化工具名称\", '@x'),\n",
    "    (\"数量\", \"@counts\")\n",
    "]\n",
    "# 画布\n",
    "p = figure(x_range=FactorRange(*x), \n",
    "           plot_height=350, \n",
    "           title=\"可视化工具Star commit contributors 数量\",\n",
    "           tooltips=TOOLTIPS\n",
    "          )\n",
    "# 柱状图\n",
    "p.vbar(x='x', top='counts', width=0.9, source=source)\n",
    "# 其他\n",
    "p.y_range.start = 0\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xaxis.major_label_orientation = 1\n",
    "p.xgrid.grid_line_color = None\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"05fb5bb4-4361-4e99-a468-0943c5d8dd91\" data-root-id=\"2720\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"ddb1aa46-bec9-49d6-bfa3-9c9a0d69839b\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"2731\"}],\"center\":[{\"id\":\"2733\"},{\"id\":\"2737\"},{\"id\":\"2766\"}],\"left\":[{\"id\":\"2734\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"2756\"},{\"id\":\"2772\"},{\"id\":\"2787\"}],\"title\":{\"id\":\"2721\"},\"toolbar\":{\"id\":\"2745\"},\"x_range\":{\"id\":\"2723\"},\"x_scale\":{\"id\":\"2727\"},\"y_range\":{\"id\":\"2725\"},\"y_scale\":{\"id\":\"2729\"}},\"id\":\"2720\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"data_source\":{\"id\":\"2719\"},\"glyph\":{\"id\":\"2770\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"2771\"},\"selection_glyph\":null,\"view\":{\"id\":\"2773\"}},\"id\":\"2772\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"source\":{\"id\":\"2719\"}},\"id\":\"2773\",\"type\":\"CDSView\"},{\"attributes\":{\"range\":{\"id\":\"2723\"}},\"id\":\"2768\",\"type\":\"Dodge\"},{\"attributes\":{\"range\":{\"id\":\"2723\"},\"value\":-0.25},\"id\":\"2752\",\"type\":\"Dodge\"},{\"attributes\":{\"label\":{\"value\":\"Commits\"},\"renderers\":[{\"id\":\"2772\"}]},\"id\":\"2782\",\"type\":\"LegendItem\"},{\"attributes\":{\"formatter\":{\"id\":\"2761\"},\"ticker\":{\"id\":\"2732\"}},\"id\":\"2731\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"2761\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"fill_color\":{\"value\":\"#c9d9d3\"},\"line_color\":{\"value\":\"#c9d9d3\"},\"top\":{\"field\":\"Star\"},\"width\":{\"value\":0.2},\"x\":{\"field\":\"tools\",\"transform\":{\"id\":\"2752\"}}},\"id\":\"2754\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"2727\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"text\":\"Fruit Counts by Year\"},\"id\":\"2721\",\"type\":\"Title\"},{\"attributes\":{\"fill_color\":{\"value\":\"#e84d60\"},\"line_color\":{\"value\":\"#e84d60\"},\"top\":{\"field\":\"Contributors\"},\"width\":{\"value\":0.2},\"x\":{\"field\":\"tools\",\"transform\":{\"id\":\"2783\"}}},\"id\":\"2785\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"2743\",\"type\":\"HelpTool\"},{\"attributes\":{\"factors\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"id\":\"2723\",\"type\":\"FactorRange\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#c9d9d3\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#c9d9d3\"},\"top\":{\"field\":\"Star\"},\"width\":{\"value\":0.2},\"x\":{\"field\":\"tools\",\"transform\":{\"id\":\"2752\"}}},\"id\":\"2755\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"2732\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"end\":30000},\"id\":\"2725\",\"type\":\"Range1d\"},{\"attributes\":{\"items\":[{\"id\":\"2767\"},{\"id\":\"2782\"},{\"id\":\"2797\"}],\"location\":\"top_left\",\"orientation\":\"horizontal\"},\"id\":\"2766\",\"type\":\"Legend\"},{\"attributes\":{\"formatter\":{\"id\":\"2759\"},\"ticker\":{\"id\":\"2735\"}},\"id\":\"2734\",\"type\":\"LinearAxis\"},{\"attributes\":{\"data_source\":{\"id\":\"2719\"},\"glyph\":{\"id\":\"2754\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"2755\"},\"selection_glyph\":null,\"view\":{\"id\":\"2757\"}},\"id\":\"2756\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"axis\":{\"id\":\"2731\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"2733\",\"type\":\"Grid\"},{\"attributes\":{\"source\":{\"id\":\"2719\"}},\"id\":\"2757\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"2764\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"2765\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"2729\",\"type\":\"LinearScale\"},{\"attributes\":{\"axis\":{\"id\":\"2734\"},\"dimension\":1,\"ticker\":null},\"id\":\"2737\",\"type\":\"Grid\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#718dbf\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#718dbf\"},\"top\":{\"field\":\"Commits\"},\"width\":{\"value\":0.2},\"x\":{\"field\":\"tools\",\"transform\":{\"id\":\"2768\"}}},\"id\":\"2771\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"2735\",\"type\":\"BasicTicker\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"2738\"},{\"id\":\"2739\"},{\"id\":\"2740\"},{\"id\":\"2741\"},{\"id\":\"2742\"},{\"id\":\"2743\"}]},\"id\":\"2745\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"2739\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"2738\",\"type\":\"PanTool\"},{\"attributes\":{\"overlay\":{\"id\":\"2744\"}},\"id\":\"2740\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"2741\",\"type\":\"SaveTool\"},{\"attributes\":{\"data\":{\"Commits\":[29503,17673,1321,2316,3370,4286],\"Contributors\":[808,357,18,98,76,184],\"Star\":[9678,11034,5387,6038,4928,3783],\"tools\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"selected\":{\"id\":\"2765\"},\"selection_policy\":{\"id\":\"2764\"}},\"id\":\"2719\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"2744\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"2742\",\"type\":\"ResetTool\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#e84d60\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#e84d60\"},\"top\":{\"field\":\"Contributors\"},\"width\":{\"value\":0.2},\"x\":{\"field\":\"tools\",\"transform\":{\"id\":\"2783\"}}},\"id\":\"2786\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"2759\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"label\":{\"value\":\"Contributors\"},\"renderers\":[{\"id\":\"2787\"}]},\"id\":\"2797\",\"type\":\"LegendItem\"},{\"attributes\":{\"data_source\":{\"id\":\"2719\"},\"glyph\":{\"id\":\"2785\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"2786\"},\"selection_glyph\":null,\"view\":{\"id\":\"2788\"}},\"id\":\"2787\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"source\":{\"id\":\"2719\"}},\"id\":\"2788\",\"type\":\"CDSView\"},{\"attributes\":{\"label\":{\"value\":\"Star\"},\"renderers\":[{\"id\":\"2756\"}]},\"id\":\"2767\",\"type\":\"LegendItem\"},{\"attributes\":{\"range\":{\"id\":\"2723\"},\"value\":0.25},\"id\":\"2783\",\"type\":\"Dodge\"},{\"attributes\":{\"fill_color\":{\"value\":\"#718dbf\"},\"line_color\":{\"value\":\"#718dbf\"},\"top\":{\"field\":\"Commits\"},\"width\":{\"value\":0.2},\"x\":{\"field\":\"tools\",\"transform\":{\"id\":\"2768\"}}},\"id\":\"2770\",\"type\":\"VBar\"}],\"root_ids\":[\"2720\"]},\"title\":\"Bokeh Application\",\"version\":\"2.2.3\"}};\n",
       "  var render_items = [{\"docid\":\"ddb1aa46-bec9-49d6-bfa3-9c9a0d69839b\",\"root_ids\":[\"2720\"],\"roots\":{\"2720\":\"05fb5bb4-4361-4e99-a468-0943c5d8dd91\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "2720"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.core.properties import value\n",
    "from bokeh.transform import dodge  \n",
    "# 数据\n",
    "tools=df['Visualization_tools']\n",
    "Star=df['Star']\n",
    "Commits=df['Commits']\n",
    "Contributors=df['Contributors']\n",
    "names=['Star','Commits','Contributors']\n",
    "data={\n",
    "    'tools':tools,\n",
    "    'Star':Star,\n",
    "    'Commits':Commits,\n",
    "    'Contributors':Contributors\n",
    "}\n",
    "source = ColumnDataSource(data=data)\n",
    "# 画布\n",
    "p = figure(x_range=tools,y_range=(0, 30000), plot_height=350, title=\"可视化工具Star commit contributors 数量\",\n",
    "\n",
    "          )\n",
    "# 绘图，采用doge数据转换，按产品种类不同年份分组显示\n",
    "p.vbar(x=dodge('tools', -0.25, range=p.x_range), top='Star', width=0.2, source=source,\n",
    "       color=\"#c9d9d3\", legend=value(\"Star\"))\n",
    "\n",
    "p.vbar(x=dodge('tools',  0.0,  range=p.x_range), top='Commits', width=0.2, source=source,\n",
    "       color=\"#718dbf\", legend=value(\"Commits\"))\n",
    "\n",
    "p.vbar(x=dodge('tools',  0.25, range=p.x_range), top='Contributors', width=0.2, source=source,\n",
    "       color=\"#e84d60\", legend=value(\"Contributors\"))\n",
    "# 其他参数设置\n",
    "\n",
    "p.xgrid.grid_line_color = None\n",
    "p.legend.location = \"top_left\"\n",
    "p.legend.orientation = \"horizontal\"\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
